package com.mtgg.common.response;



import java.io.Serializable;


/**
 * @Author: 亦善
 * @Date: 2020/5/13 11:25
 * @Describe: 
 */
public class ServerResponse<T> extends Response<T> implements Serializable {

    private boolean isSuccess(){
        return super.getCode() == ResponseCode.SUCCESS.getCode();
    }

//    public boolean isFailure(){
//        return super.getCode() != ResponseCode.SUCCESS.getCode();
//    }

    private ServerResponse(int status){
        super.setCode(status);
        super.setMessage(ResponseCode.SUCCESS.getDesc());
        super.setData(null);
    }
    private ServerResponse(int status, T data){
        super.setCode(status);
        super.setMessage(ResponseCode.SUCCESS.getDesc());
        super.setData(data);
    }

    private ServerResponse(int status, String msg, T data){
        super.setCode(status);
        super.setData(data);
        super.setMessage(msg);
    }

    private ServerResponse(int status, String msg){
        super.setCode(status);
        super.setMessage(msg);
        super.setData(null);
    }

    public static <T> ServerResponse<T> createBySuccess(){
        return new ServerResponse<T>(ResponseCode.SUCCESS.getCode());
    }

    public static <T> ServerResponse<T> createBySuccessMessage(String msg){
        return new ServerResponse<T>(ResponseCode.SUCCESS.getCode(),msg);
    }

    public static <T> ServerResponse<T> createBySuccess(T data){
        return new ServerResponse<T>(ResponseCode.SUCCESS.getCode(),data);
    }

    public static <T> ServerResponse<T> createBySuccess(String msg,T data){
        return new ServerResponse<T>(ResponseCode.SUCCESS.getCode(),msg,data);
    }

    public static <T> ServerResponse<T> createByError(){
        return new ServerResponse<T>(ResponseCode.ERROR.getCode(),ResponseCode.ERROR.getDesc());
    }

    public static <T> ServerResponse<T> createByErrorMessage(String errorMessage){
        return new ServerResponse<T>(ResponseCode.ERROR.getCode(),errorMessage);
    }

    public static <T> ServerResponse<T> createByParameterError(String errorMessage){
        return new ServerResponse<T>(ResponseCode.PARAMETER_ERROR.getCode(),errorMessage);
    }

    public static <T> ServerResponse<T> createByResourceNull(String errorMessage){
        return new ServerResponse<T>(ResponseCode.RESOURCES_ERROR.getCode(),errorMessage);
    }

    public static <T> ServerResponse<T> createByErrorCodeMessage(int errorCode,String errorMessage){
        return new ServerResponse<T>(errorCode,errorMessage);
    }

    public static <T> ServerResponse<T> createByCodeMessageData(int errorCode,String message,T data){
        return new ServerResponse<T>(errorCode,message,data);
    }

}
